const router = require('koa-router')();
const fs = require("fs")
const path = require("path")

const path_content = path.resolve(__dirname,"../../editor/src/utils/content.json")
console.log("path_content",path_content)

router.post("/changeContent",async (ctx)=>{
  let params = ctx.request.body
  let content = params.data
  console.log("content",JSON.stringify(content))
  fs.writeFile(path_content,JSON.stringify(content),"utf8",(err)=>{
    if(err){return ctx.body = {status:400,msg:err}}
    ctx.body = {status:200,msg:"ok"}
  })
})

module.exports = router